package com.liwei.app;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MyApp2 {
    public static void main(String[] args) {
        try {
            Class aClass = Class.forName("com.liwei.beans.Stu");
            //获得构造方法对象
            Constructor constructor = aClass.getConstructor();
            Object o = constructor.newInstance();
            //调用fun1方法
            Method fun1 = aClass.getDeclaredMethod("fun1");
            //开启权限
            fun1.setAccessible(true);
            //调用方法
            fun1.invoke(o);
            //调用fun2方法
            Method fun2 = aClass.getDeclaredMethod("fun2", int.class, int.class);
            fun2.setAccessible(true);
            fun2.invoke(o,100,200);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
